#include <iostream>
#include <memory>

using namespace std;

std::weak_ptr<int> gw;

void f()
{
    std::shared_ptr<int> gsp = gw.lock();
    if (nullptr != gsp)
    {
        cout << *gsp << endl;
    }
    else
    {
        cout << "expired" << endl;
    }
}

int main(int argc, char *argv[])
{
    {
        std::shared_ptr<int> gs = std::make_shared<int>(42);
        gw = gs;
        f();
    }

    f();
    return 0;
}
